package com.hyt.it.ogt.controller.ykcj.exam;

import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.ykcj.common.annotation.Log;
import com.hyt.it.ogt.ykcj.common.core.domain.AjaxResult;
import com.hyt.it.ogt.ykcj.common.core.page.TableDataInfo;
import com.hyt.it.ogt.ykcj.common.enums.BusinessType;
import com.hyt.it.ogt.ykcj.domain.param.EnterpriseExamSaveParam;
import com.hyt.it.ogt.ykcj.domain.param.ExamPageParam;
import com.hyt.it.ogt.ykcj.domain.vo.EnterpriseExamVo;
import com.hyt.it.ogt.ykcj.service.exam.IExamInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 企业招聘考试信息Controller
 *
 * @author admin
 * @date 2021-06-18
 */
@Api(tags = "exam.9.企业招聘考试信息", value = "企业招聘考试信息请求接口")
@ApiSort(value = 109)
@RestController
@RequestMapping("/enterprise/exam/info")
public class EnterpriseExamInfoController extends BaseController {
    @Autowired
    private IExamInfoService examInfoService;

    /**
     * 查询考试信息列表
     */
    @ApiOperation(value = "查询考试信息列表", response = EnterpriseExamVo.class)
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ExamPageParam examPageParam) {
        String officeId = getOfficeId();
        Set<String> deptIds = getDeptIds();
        examPageParam.setOfficeId(officeId)
                .setDeptIds(deptIds);
        
        startPage();
        List<EnterpriseExamVo> list = examInfoService.pageEnterpriseExamInfoList(examPageParam);
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setTotal(examPageParam.getTotal() == null ? 0L : examPageParam.getTotal());
        return dataTable;
    }

    /**
     * 获取考试信息详细信息
     *
     * @throws Exception
     */
    @ApiOperation("获取考试信息详细信息")
    @ApiImplicitParam(name = "id", value = "考试ID", dataType = "String", required = true)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(examInfoService.enterpriseExamDetail(id));
    }

    /**
     * 新增考试信息
     */
    @ApiOperation("新增/编辑考试信息")
    @Log(title = "考试信息", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult add(@RequestBody EnterpriseExamSaveParam enterpriseExamSaveParam) {
        examInfoService.insertEnterpriseExamInfo(enterpriseExamSaveParam);
        return AjaxResult.success();
    }

    /**
     * 删除考试信息
     *
     * @throws Exception
     */
    @ApiOperation("删除考试信息")
    @Log(title = "考试信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult remove(String ids) {
        if (ids == null || ids.length() == 0) {
            return AjaxResult.error("参数不能为空");
        }
        examInfoService.deleteEnterpriseExamInfoByIds(ids);
        return AjaxResult.success();
    }

}


